package com.wlz.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
import org.springframework.cloud.zookeeper.discovery.ZookeeperServiceWatch;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

/**
 * @author wlz
 * @date 2022-06-26  7:01 下午
 */
@Configuration
@Slf4j
public class HeartbeatEventListener implements ApplicationListener<HeartbeatEvent> {

    @Override
    public void onApplicationEvent(HeartbeatEvent event) {
        Object value = event.getValue();
        ZookeeperServiceWatch source = (ZookeeperServiceWatch)event.getSource();
        log.info(" event:source: {} ,event:value{}",source.getCache().getCurrentChildren("/services"),value.toString());
    }
}
